/**
 * Created by Administrator on 2017\9\21 0021.
 *Platform home
 */
import React from 'react';
import {Link} from 'react-router-dom';
import { Row,Col,Input,Button } from 'antd';
import template from './../../commonui/template';
import MenuList from './MenuList';
import PlatPage from './adminPage';
import PlatChk from './PlatAuth'
const Search = Input.Search;


 class PlatHome extends React.Component{
    constructor(props){
        super(props);
        this.search=this.search.bind(this);
        this.drawUserList=this.drawUserList.bind(this);
        this.changePage=this.changePage.bind(this);
        this.drawPage=this.drawPage.bind(this);
        this.Operation=this.Operation.bind(this);
        this.Delete=this.Delete.bind(this);
        const data =['ww','23','44'];
        this.state={
            usrList:data,
            page:'add'
        }
    }
    search(){

    }
    drawUserList(){
        let userlists = this.state.usrList.map((option,index)=>{
            console.log(option);
            return (
                <li key={index}>{option}</li>
                )
        })
        return userlists;
    }
    changePage(e){
        if(e&&e.target.id!=this.state.page){
            this.setState({
                page:e.target.id
            })
        }
    }
    drawPage(){
        if(this.state.page==='add'){
            return  <PlatPage/>
        }else{
            return (
                <div>
                    <h2>Test</h2>
                </div>
            )
        }
    }
    Operation(){
            return (
                <div>
                    <div onClick={this.changePage}>
                        <Button id="add" type="primary">Add</Button>
                        <Button id="edit">Edit</Button>
                        <Button id="delete" type="danger" onClick={this.Delete}>Delete</Button>
                    </div>
                    <div>
                        {this.drawPage()}
                    </div>
                </div>
            )
    }
    Delete(){
        /***ajax 删除**/
    }
    render(){
        return (
            <div>
                <Row>
                    <Col span={6}>
                         <MenuList/>
                    </Col>
                    <Col span={18}>
                        <Row>
                            <Col span={8}>
                                <div>
                                    <Search placeholder="Search User" style={{width:200}} onSearch={this.search}/>
                                </div>
                                <div>
                                    <ul>
                                    {this.drawUserList()}
                                    </ul>
                                </div>
                            </Col>
                            <Col span={16}>
                                <Row>
                                    {this.Operation()}
                                </Row>
                                <Row>
                                    <PlatChk/>
                                </Row>
                            </Col>
                        </Row>
                    </Col>
                </Row>

            </div>
        )
    }

}
export default template({
    id: 'PlatHome',
    component: PlatHome
});